<?php
/**
* Change logs
* Mar 3, 2011 - trungdt - Add support media type
*                         ALTER TABLE `ag_musics` ADD `file_type` INT( 1 ) NOT NULL DEFAULT '-1' COMMENT '=0: FLV; =1: embed code; =2: WMV'  
*                         ALTER TABLE `ag_musics` ADD `embed_code` TEXT NOT NULL   
*/
class musics {
	function form($object) {
		if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
		exponent_forms_initialize();
		global $db;
		$form = new form();
		if (!isset($object->id)) {
			$object->name = '';
			$object->info='';
			$object->album_id=0;
			$object->composer_id=0;
			$object->high_quality=0;
			$object->sound_trackmix=0;
			$object->demo=0;
			$object->sheet_music=0;
			$object->tongpho=0;
			$object->top_hit=0;
			$object->singer='';
			$object->length=0;
            // Mar 3, 2011 - trungdt - add support media type - begin
            $object->file_type=0; // =0: FLV; =1: Embed code, = 2: Silverlight/WMV
            $object->embed_code='';
            // Mar 3, 2011 - trungdt - add support media type - end
		} else {
			$form->meta('id',$object->id);
		}
		
		// get config of the album
		$album=$db->selectObject("album","id = ".$_REQUEST['album_id']);
		$album_loc = "";
    if ($album)
      $album_loc=$album->location_data;
      $config=$db->selectObject("albummodule_config","location_data = '".$album_loc."'");
    if (!$config)
    {		 	 	 	 	 	 	 
 	    $config->hquality_collection=0;		 	 	 	 	 	 	 
 	    $config->album_type=0;
    }
    // end of album config
		
		// get all composer
		$composer=$db->selectDropdown('composers','name','composer_type = ' . $config->album_type);
		$default_composer = 0;
		if ($object->composer_id == '')
		{
			$object->composer_id=$default_composer;
		}
		
		// get all album
		$album=$db->selectDropdown('album','name','album_type = ' . $config->album_type);
		$default_album = -1;
		foreach ($album as $mvalue=>$mcaption)
		{
			if ($mvalue == $_REQUEST['album_id'])
				{$default_album=$mvalue;break;}
		}
		$object->album_id=$default_album;
		
		
		$form->register('name','Name',new textcontrol($object->name,50,false,200));
		$form->register('singer','Singer',new textcontrol($object->singer,50,false,200));
    $form->register('album_id','Album',new dropdowncontrol($object->album_id,$album,true));
		//$form->register('composer_id','Composer',new dropdowncontrol($object->composer_id,$composer,true));
		$form->register('info','Info',new htmleditorcontrol($object->info));
		
    // 8/18/2009: immanuel192 commented this code to obtain the contract
    //$form->register('demo','Demo file', new ajax_select_file('demo',1,$object->demo,false));
		//$form->register('sound_trackmix','Sound track mix file', new ajax_select_file('sound_trackmix',1,$object->sound_trackmix,false));
		//$form->register('sheet_music','Sheet file', new ajax_select_file('sheet_music',1,$object->sheet_music,false));
		//$form->register('tongpho','Tổng phổ', new ajax_select_file('tongpho',1,$object->tongpho,false));
		//$form->register('top_hit','Top hit?', new checkboxcontrol($object->top_hit));
        
        // Mar 3, 2011 - trungdt - add support media type - begin
            $file_type=array();
            $file_type[0]="FLV - Flash media";
            $file_type[1]="Embed Code - Youtube, Vimeo,..";
            $file_type[2]="WMV - Windows media player/Silverlight";
            $file_type[3]="MP3 - Flash mp3 player";
            $form->register('file_type',"File Type",new dropdowncontrol($object->file_type,$file_type));
            $form->register('high_quality','High quality file', new ajax_select_file('high_quality',$config->hquality_collection,$object->high_quality,true));
            $form->register('embed_code',"Embed Code",new texteditorcontrol($object->embed_code,10,50));
        // Mar 3, 2011 - trungdt - add support media type - end    
        
		$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
		return $form;
	}
	
	function update($values,$object) {
		$object->name = $values['name'];
		$object->info = $values['info'];
		$object->singer = $values['singer'];
		$object->album_id = $values['album_id'];
        $object->file_type = intval($values['file_type']);
        $object->embed_code = $values['embed_code'];
		//$object->composer_id = $values['composer_id'];
		//$object->top_hit = $values['top_hit'];
		$object->high_quality = $values['high_quality'];
		return $object;
	}
}

?>
